home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / gui / infobox / emailpanels.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  17KB  |  447 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import with_statement
  5. import sys
  6. import wx
  7. from wx import Rect, RectS, RectPS, BLACK
  8. from datetime import datetime
  9. from gui import skin
  10. from gui.textutil import default_font, CopyFont
  11. from gui.skin.skinobjects import SkinColor
  12. from gui.toolbox import add_image_text
  13. from gui.uberwidgets.pseudosizer import PseudoSizer
  14. from gui.uberwidgets.clearlink import ClearLink
  15. from cgui import SimplePanel
  16. from common import actions
  17. from util import do
  18. link_style = wx.NO_BORDER | wx.HL_ALIGN_LEFT | wx.TRANSPARENT_WINDOW
  19.  
  20. class Header(SimplePanel):
  21.     
  22.     def __init__(self, parent):
  23.         SimplePanel.__init__(self, parent)
  24.         self.account = None
  25.         self.Bind(wx.EVT_PAINT, self.OnPaint)
  26.         self.linkage = PseudoSizer()
  27.         self.UpdateSkin()
  28.  
  29.     
  30.     def SetAccount(self, account):
  31.         if account is self.account:
  32.             return None
  33.         
  34.         if self.account is not None:
  35.             
  36.             try:
  37.                 self.account.unobserve_count(self.Refreshxor)
  38.             except NotImplementedError:
  39.                 pass
  40.  
  41.             
  42.             try:
  43.                 self.account.unobserve_state(self.Refreshxor)
  44.             except NotImplementedError:
  45.                 pass
  46.             except:
  47.                 None<EXCEPTION MATCH>NotImplementedError
  48.             
  49.  
  50.         None<EXCEPTION MATCH>NotImplementedError
  51.         self.account = account
  52.         self.icon = account.icon.Resized(16)
  53.         self.linkage.Clear(True)
  54.         for linkfunc in account.header_funcs:
  55.             link = ClearLink(self, -1, linkfunc[0], (lambda l = (linkfunc,): self.do_link(l)), style = link_style, pos = (-400, -400))
  56.             link.NormalColour = link.HoverColour = link.VisitedColour = self.linkfc
  57.             link.Font = self.linkfont
  58.             self.linkage.Add(link)
  59.         
  60.         self.linkage.Layout()
  61.         
  62.         try:
  63.             account.observe_count(self.Refreshxor)
  64.         except NotImplementedError:
  65.             pass
  66.  
  67.         
  68.         try:
  69.             account.observe_state(self.Refreshxor)
  70.         except NotImplementedError:
  71.             pass
  72.  
  73.         self.Refresh(False)
  74.  
  75.     
  76.     def do_link(self, link):
  77.         if len(link) > 2:
  78.             if link[2]:
  79.                 wx.GetTopLevelParent(self).Hide()
  80.             
  81.         else:
  82.             wx.GetTopLevelParent(self).Hide()
  83.         if callable(link[1]):
  84.             link[1]()
  85.         else:
  86.             wx.LaunchDefaultBrowser(link[1])
  87.  
  88.     
  89.     def Refreshxor(self, *a):
  90.         self.Refresh(False)
  91.  
  92.     
  93.     def UpdateSkin(self):
  94.         self.padding = wx.Point(4, 4)
  95.         self.headerfont = skin.get('infobox.fonts.header', (lambda : default_font()))
  96.         self.linkfont = CopyFont(skin.get('infobox.fonts.link', (lambda : default_font())), underline = True)
  97.         self.headerfc = skin.get('infobox.fontcolors.navbarheader', (lambda : wx.BLACK))
  98.         self.linkfc = skin.get('infobox.fontcolors.navbarlink', (lambda : wx.BLUE))
  99.         linkposy = self.headerfont.Height + 2 * self.padding[1]
  100.         linkposx = self.padding[0] * 2 + 16
  101.         self.linkage.SetPosition((linkposx, linkposy))
  102.         for link in self.linkage:
  103.             link.NormalColour = link.HoverColour = link.VisitedColour = self.linkfc
  104.             link.Font = self.linkfont
  105.         
  106.         self.linkage.Layout()
  107.         self.bg = skin.get('infobox.backgrounds.header', (lambda : SkinColor(wx.Color(225, 255, 225))))
  108.         self.Size = self.MinSize = wx.Size(-1, self.headerfont.Height + self.linkfont.Height + self.padding.y * 4)
  109.  
  110.     
  111.     def OnPaint(self, event):
  112.         dc = wx.BufferedPaintDC(self)
  113.         rect = RectS(self.Size)
  114.         (padx, pady) = self.padding
  115.         self.bg.Draw(dc, rect)
  116.         dc.Font = self.headerfont
  117.         font_height = self.headerfont.Height
  118.         dc.TextForeground = self.headerfc
  119.         dc.DrawBitmap(self.icon, padx, padx + font_height // 2 - self.icon.Height // 2, True)
  120.         printable = rect.width - padx
  121.         curserx = rect.x + 2 * padx + self.icon.Width
  122.         cursery = rect.y + pady
  123.         dc.DrawLabel(self.account.display_name, wx.Rect(curserx, cursery, printable - curserx, font_height))
  124.         curserx += dc.GetTextExtent(self.account.display_name + ' ')[0]
  125.         if getattr(self.account, 'service', None) != 'twitter':
  126.             None(dc.DrawLabel if not hasattr(self.account, 'count') else '(' + str(self.account.count) + ')', Rect(curserx, cursery, printable - curserx, dc.Font.Height))
  127.         
  128.  
  129.  
  130.  
  131. class EmailList(wx.VListBox):
  132.     
  133.     def __init__(self, parent):
  134.         wx.VListBox.__init__(self, parent)
  135.         import common.favicons as common
  136.         common.favicons.on_icon += self.OnFaviconReceived
  137.         self.emails = []
  138.         self.account = None
  139.         self.itemheight = 0
  140.         self.SetItemCount(len(self.emails))
  141.         self.linkage = PseudoSizer()
  142.         self.linkage.Show(False)
  143.         self.errorlink = None
  144.         self.UpdateSkin()
  145.         links = [
  146.             ('olink', 'Open', 'OnClickEmail'),
  147.             ('rlink', 'Mark as Read', 'markAsRead'),
  148.             ('alink', 'Archive', 'archive'),
  149.             ('dlink', 'Delete', 'delete'),
  150.             ('slink', 'Report Spam', 'reportSpam')]
  151.         for attr, text, method in links:
  152.             link = ClearLink(self, -1, text, method, style = wx.NO_BORDER | wx.HL_ALIGN_CENTRE)
  153.             link.Font = self.linkfont
  154.             setattr(self, attr, link)
  155.             self.linkage.Add(link)
  156.         
  157.         self.BBind(HYPERLINK = self.OnLink, MOTION = self.OnMouseMotion, LEFT_DCLICK = self.OnDblClick, LEAVE_WINDOW = self.OnMouseOut, MOUSEWHEEL = self.OnMouseWheel, PAINT = self.OnPaint, SHOW = self.OnShow)
  158.         self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
  159.  
  160.     
  161.     def OnFaviconReceived(self, domain):
  162.         get_icon_domain = get_icon_domain
  163.         import common.favicons
  164.         for i, email in enumerate(self.emails):
  165.             if not email.domain:
  166.                 continue
  167.             
  168.             if domain == get_icon_domain(email.domain):
  169.                 self.RefreshLine(i)
  170.                 continue
  171.         
  172.  
  173.     
  174.     def OnMouseWheel(self, event):
  175.         self.ScrollLines(-(event.WheelRotation) // abs(event.WheelRotation))
  176.  
  177.     
  178.     def OnDblClick(self, event):
  179.         self.account.OnClickEmail(self.account.emails[self.Selection])
  180.  
  181.     
  182.     def OnMouseOut(self, event):
  183.         if not self.linkage.Rect.Contains(event.Position) and self.Selection != -1:
  184.             self.RefreshLine(self.Selection)
  185.             self.Selection = -1
  186.             self.linkage.Show(False)
  187.         
  188.  
  189.     
  190.     def OnMouseMotion(self, event):
  191.         i = self.HitTest(event.Position)
  192.         if self.Selection != i:
  193.             oldSelection = self.Selection
  194.             self.Selection = i
  195.             if self.Selection == -1:
  196.                 self.linkage.Show(False)
  197.             else:
  198.                 self.linkage.Show(True)
  199.             if oldSelection >= 0:
  200.                 self.RefreshLine(oldSelection)
  201.             
  202.             if self.Selection >= 0:
  203.                 self.RefreshLine(self.Selection)
  204.             
  205.         
  206.  
  207.     
  208.     def OnShow(self, event):
  209.         event.Skip()
  210.         if wx.IsDestroyed(self):
  211.             print >>sys.stderr, 'WARNING: emailpanels.py OnShow called, but is destroyed'
  212.             return None
  213.         
  214.         if not (self.Shown) and self.account is not None:
  215.             self.account.emails.remove_observer(self.ListChanged)
  216.         
  217.         self.Selection = -1
  218.         self.linkage.Show(False)
  219.         self.Refresh(False)
  220.  
  221.     
  222.     def SetAccount(self, account):
  223.         self.ScrollToLine(0)
  224.         self.Selection = -1
  225.         self.linkage.Show(False)
  226.         if self.account is not None:
  227.             self.account.emails.remove_observer(self.ListChanged)
  228.         
  229.         self.account = account
  230.         self.account.emails.add_observer(self.ListChanged)
  231.         self.ListChanged()
  232.         acts = actions.forclass(account)
  233.         fnames = [ _[1] if not isinstance(act, basestring) else None for act in acts ]
  234.         self.olink.Show('open' in fnames)
  235.         self.rlink.Show('markAsRead' in fnames)
  236.         self.alink.Show('archive' in fnames)
  237.         self.dlink.Show('delete' in fnames)
  238.         self.slink.Show('reportSpam' in fnames)
  239.         self.linkage.Layout()
  240.         self.itemheight = [] + self.padding.y * 4 + self.titlefont.Height + self.majorfont.Height + self.linkfont.Height if self.sep else 0
  241.         if account.can_has_preview:
  242.             self.itemheight += self.minorfont.Height + self.padding.y
  243.         
  244.         self.RefreshAll()
  245.         self.Show(True)
  246.         self.Frozen().__enter__()
  247.         
  248.         try:
  249.             self.GrandParent.DoSizeMagic()
  250.         finally:
  251.             pass
  252.  
  253.  
  254.     
  255.     def ListChanged(self, *args, **kwargs):
  256.         i = self.GetFirstVisibleLine()
  257.         
  258.         try:
  259.             topemail = self.emails[i]
  260.         except IndexError:
  261.             topemail = None
  262.  
  263.         self.emails = self.account.emails
  264.         self.Frozen().__enter__()
  265.         
  266.         try:
  267.             self.SetItemCount(len(self.emails))
  268.             self.GrandParent.DoSizeMagic()
  269.             if topemail is not None:
  270.                 
  271.                 try:
  272.                     i = self.emails.index(topemail)
  273.                 except ValueError:
  274.                     self.Frozen()
  275.                     self.Frozen()
  276.                 except:
  277.                     self.Frozen()<EXCEPTION MATCH>ValueError
  278.                 
  279.  
  280.             self.Frozen()
  281.             self.ScrollLines(i)
  282.         finally:
  283.             pass
  284.  
  285.         self.Parent.Refresh(False)
  286.  
  287.     
  288.     def UpdateSkin(self):
  289.         s = skin.get
  290.         self.padding = s('infobox.padding', (lambda : wx.Point(4, 4)))
  291.         self.headerfont = s('infobox.fonts.header', default_font)
  292.         self.titlefont = s('infobox.fonts.title', default_font)
  293.         self.majorfont = s('infobox.fonts.major', default_font)
  294.         self.minorfont = s('infobox.fonts.minor', default_font)
  295.         self.linkfont = CopyFont(s('infobox.fonts.link', default_font), underline = True)
  296.         fc = s('infobox.fontcolors')
  297.         g = fc.get
  298.         self.titlefc = g('title', BLACK)
  299.         self.majorfc = g('major', wx.BLACK)
  300.         self.minorfc = g('minor', wx.Color(128, 128, 128))
  301.         self.linkfc = g('link', wx.BLUE)
  302.         self.hovertitlefc = g('emailhovertitle', self.titlefc)
  303.         self.hovermajorfc = g('emailhovermajor', self.majorfc)
  304.         self.hoverminorfc = g('emailhoverminor', self.minorfc)
  305.         self.hoverlinkfc = g('emailhoverlink', self.linkfc)
  306.         for link in self.linkage:
  307.             link.NormalColour = link.HoverColour = link.VisitedColour = self.hoverlinkfc
  308.             link.Font = self.linkfont
  309.         
  310.         self.linkage.Layout()
  311.         if self.errorlink:
  312.             self.errorlink.Font = self.Parent.Font
  313.             self.errorlink.VisitedColour = self.errorlink.HoverColour = self.errorlink.NormalColour = s('infobox.linkcolor', (lambda : wx.BLUE))
  314.         
  315.         self.bg = s('infobox.backgrounds.email', (lambda : SkinColor(wx.WHITE)))
  316.         self.selbg = s('infobox.backgrounds.emailhover', (lambda : SkinColor(wx.Color(225, 255, 225))))
  317.         self.sep = s('infobox.shortseparatorimage', None)
  318.  
  319.     
  320.     def GetFullHeight(self):
  321.         if not self.ItemCount:
  322.             pass
  323.         return 1 * self.OnMeasureItem(0)
  324.  
  325.     
  326.     def SkimIt(self, it):
  327.         if self.ItemCount:
  328.             h = self.OnMeasureItem(0)
  329.             r = (it // h) * h
  330.             return r
  331.         
  332.         return self.OnMeasureItem(0)
  333.  
  334.     
  335.     def OnMeasureItem(self, n):
  336.         return self.itemheight
  337.  
  338.     
  339.     def OnDrawBackground(self, dc, rect, n):
  340.         if self.Selection == n:
  341.             self.selbg.Draw(dc, rect, n)
  342.         else:
  343.             self.bg.Draw(dc, rect, n)
  344.  
  345.     
  346.     def OnPaint(self, event):
  347.         if self.ItemCount:
  348.             event.Skip()
  349.             return None
  350.         
  351.         dc = wx.BufferedPaintDC(self)
  352.         rect = RectS(self.Size)
  353.         self.OnDrawBackground(dc, rect, 0)
  354.         dc.Font = self.titlefont
  355.         None(dc.DrawLabel if self.account.count else 'No New Email', rect, wx.ALIGN_CENTER)
  356.  
  357.     
  358.     def OnDrawItem(self, dc, rect, n):
  359.         issel = n == self.Selection
  360.         email = self.emails[n]
  361.         pad = self.padding
  362.         sendtime = getattr(email, 'sendtime', None)
  363.         if hasattr(sendtime, 'strftime'):
  364.             strf = sendtime.strftime
  365.             iscurdate = strf('%b %d %y') == datetime.now().strftime('%b %d %y')
  366.             date = strf('%b %d')
  367.             time = strf('%I:%M %p')
  368.             if time[0] == '0':
  369.                 time = time[1:]
  370.             
  371.             if iscurdate and getattr(self.account, 'timestamp_is_time', (lambda t: True))(sendtime):
  372.                 timestamp = time
  373.             else:
  374.                 timestamp = date
  375.         else:
  376.             timestamp = sendtime
  377.         if timestamp is None:
  378.             timestamp = ''
  379.         
  380.         curserx = rect.x + pad.x
  381.         cursery = rect.y + pad.y
  382.         favicon = favicon
  383.         import common.favicons
  384.         d = email.domain
  385.         icon = None if d is not None else None
  386.         iconsize = 16
  387.         if icon is None:
  388.             icon = skin.get('emailpanel.miscicons.defaulticon', None)
  389.         
  390.         if icon is not None:
  391.             icon = icon.Resized(iconsize)
  392.             dc.DrawBitmap(icon, curserx, cursery, True)
  393.         
  394.         curserx += iconsize + pad.x
  395.         dc.Font = self.minorfont
  396.         dc.TextForeground = None if issel else self.minorfc
  397.         tste = dc.GetFullTextExtent(timestamp)
  398.         tsrect = wx.Rect(rect.x + rect.width - tste[0] - pad.x, cursery, tste[0], tste[1] + tste[2] + tste[3])
  399.         dc.DrawTruncatedText(timestamp, tsrect)
  400.         if email.attachments:
  401.             atticon = skin.get('emailpanel.miscicons.attachmenticon', None)
  402.             if atticon is not None:
  403.                 count = len(email.attachments)
  404.                 if count > 1:
  405.                     atticon = add_image_text(atticon, str(count))
  406.                 
  407.                 dc.DrawBitmap(atticon, tsrect.X - atticon.Width - pad.x, tsrect.Y, True)
  408.             
  409.         
  410.         dc.Font = self.titlefont
  411.         dc.TextForeground = None if issel else self.titlefc
  412.         if not email.fromname:
  413.             pass
  414.         dc.DrawTruncatedText(u'%s' % email.fromemail, Rect(curserx, cursery, rect.Width - curserx + pad.x - tsrect.width, dc.Font.Height))
  415.         cursery += dc.Font.Height + self.padding.y
  416.         dc.Font = self.majorfont
  417.         dc.TextForeground = None if issel else self.majorfc
  418.         if not email.subject:
  419.             pass
  420.         dc.DrawTruncatedText(_('(No Subject)'), Rect(curserx, cursery, rect.Width - curserx + pad.x, dc.Font.Height))
  421.         if self.account.can_has_preview:
  422.             cursery += dc.Font.Height + pad.y
  423.             dc.Font = self.minorfont
  424.             dc.TextForeground = None if issel else self.minorfc
  425.             if not email.content:
  426.                 pass
  427.             dc.DrawTruncatedText(_('(No Preview)'), wx.Rect(curserx, cursery, rect.Width - curserx + pad.x, dc.Font.Height))
  428.         
  429.         if self.sep and n < len(self.emails) - 1:
  430.             self.sep.Draw(dc, wx.RectPS(rect.Position + (2, rect.height - self.sep.Size.height), (rect.width - 4, self.sep.Size.height)))
  431.         
  432.         if issel:
  433.             cursery += dc.Font.Height + pad.y
  434.             self.linkage.SetPosition((curserx, cursery))
  435.         
  436.  
  437.     
  438.     def OnLink(self, event):
  439.         if event.URL == 'OnClickEmail':
  440.             wx.GetTopLevelParent(self).Hide()
  441.         
  442.         getattr(self.account, event.URL)(self.account.emails[self.Selection])
  443.         self.Selection = -1
  444.         self.linkage.Show(False)
  445.  
  446.  
  447.